﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace sieuthiIT
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("moi nhap tap tin can tao vd(c:\\data.txt)");
            string tenfile = Console.ReadLine();
            //tao hoac mo file muc dich de ghi dl
            FileStream fs = new FileStream(tenfile, FileMode.OpenOrCreate, FileAccess.Write);
            //tao luong ghi
            StreamWriter wt = new StreamWriter(fs);
            //phuong thuc chi dinh ghi vao cuoi file
            fs.Seek(0, SeekOrigin.End);
            Console.WriteLine("moi ban nhap noi dung can ghi");
            string noidung = Console.ReadLine();
            wt.WriteLine(noidung);
            wt.Flush();
            wt.Close();
            //===================*********================
            FileStream fs1 = new FileStream(tenfile, FileMode.Open, FileAccess.Read);
            // tạo luồng để đọc file
            StreamReader rd = new StreamReader(fs1);
            fs1.Seek(0,SeekOrigin.Begin);//doc tu dau file
            string noidung1= rd.ReadToEnd();
            Console.WriteLine(noidung1);
            rd.Close();
            fs1.Close();
        }
    }
}
